package collection.exercise;

import java.util.HashSet;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA
 * Description:HashSet练习
 * User:22954
 * Date:2024-02-09
 * Time:3:37
 */
@SuppressWarnings("all")
public class Exercise5 {
    public static void main(String[] args) {
        HashSet<Employee_> employeeS = new HashSet<>();
        employeeS.add(new Employee_("zhangsan",1000,new MyDate(2000,1,1)));
        employeeS.add(new Employee_("zhangsan",1000,new MyDate(1999,1,1)));
        employeeS.add(new Employee_("wanger",1000,new MyDate(2000,1,1)));
        employeeS.add(new Employee_("zhangsan",1000,new MyDate(2000,1,1)));
        System.out.println(employeeS);
        //[Employee_{name='wanger', sal=1000, birthday=MyDate{year=2000, month=1, day=1}}, Employee_{name='zhangsan', sal=1000, birthday=MyDate{year=2000, month=1, day=1}}, Employee_{name='zhangsan', sal=1000, birthday=MyDate{year=1999, month=1, day=1}}]
    }
}
@SuppressWarnings("all")
class Employee_{
    private String name;
    private int sal;
    private MyDate birthday;

    public Employee_(String name, int sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee_ employee = (Employee_) o;
        return Objects.equals(name, employee.name) && Objects.equals(birthday, employee.birthday);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, birthday);
    }

    @Override
    public String toString() {
        return "Employee_{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthday=" + birthday +
                '}';
    }
}
@SuppressWarnings("all")
class MyDate{
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year && month == myDate.month && day == myDate.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
}
